/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view;

import com.sun.lwuit.Command;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.layouts.BoxLayout;
import core.NotificationManager;
import core.ScreenEngine;
import view.additional.CellItem;
import view.additional.MenuList;
import view.commands.BackCommand;

/**
 *
 * @author Kvest
 */
public class NotificationsListForm extends BasicForm implements MenuList.MenuListSelection
{
    public static final int OK_COMMAND_ID = 0;
    
    private MenuList items;
    
    private NotificationEditForm notificationEditForm;
    
    public NotificationsListForm() 
    {
        super("edit_notif");
            
        init();
    }
    
    private void init()
    {
        setLayout(new BoxLayout(BoxLayout.Y_AXIS));
        setScrollable(false);
        
        //Заполняем меню
        items = new MenuList();
        items.addItem(new CellItem(NotificationManager.NEW_ORDER ,"incoming_order"));
        items.addItem(new CellItem(NotificationManager.NEW_MESSAGE ,"incoming_message"));
        items.addItem(new CellItem(NotificationManager.ORDER_STATE_CHANGED ,"incoming_status"));
        items.addItem(new CellItem(NotificationManager.ORDER_CANCELED ,"incoming_close"));
        items.addItem(new CellItem(NotificationManager.CONNECTION_ERROR ,"net_error"));
        items.addItem(new CellItem(NotificationManager.NEW_EFIR_ORDER ,"efir_order"));
        items.setSelectionListener(this);
        addComponent(items);
        
        //Команды
        addCommand(new BackCommand());
        
        Command ok = new Command("ok", OK_COMMAND_ID)
        {
            public void actionPerformed(ActionEvent evt)
            {
                itemSelected(items.getSelectedId());
                
                evt.consume();
            }
        };
        addCommand(ok);
    }
    
    public void itemSelected(int id)
    {
        if (notificationEditForm == null)
        {
            notificationEditForm = new NotificationEditForm();
        }
        
        //Устанавливаем данные
        notificationEditForm.setNotification(NotificationManager.getNotificationManager().getNotification(id));
        
        //Отображаем
        ScreenEngine.getEngine().push(notificationEditForm);
    }
}
